<?php
/**
 * Created by PhpStorm.
 * User: zhangrongxiang
 * Date: 2017/5/25
 * Time: 下午2:22
 */


include "../../../vendor/autoload.php";


use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Writer\SvgWriter;
use Symfony\Component\HttpFoundation\Response;

// Create a QR code
$qrCode = new QrCode('Life is too short to be generating QR codes');
$qrCode->setSize(300);

// Set advanced options
$qrCode
    ->setMargin(10)
    ->setEncoding('UTF-8')
    ->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH)
    ->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0])
    ->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255])
    ->setLabel('Scan the code', 16, null/*__DIR__.'/../assets/noto_sans.otf'*/, LabelAlignment::CENTER)
    ->setLogoPath("./cloud.jpg"/*__DIR__.'/'*/)
    ->setLogoSize(10)
    ->setValidateResult(true)
;

// Output the QR code
header('Content-Type: '.$qrCode->getContentType(PngWriter::class));
echo $qrCode->writeString(PngWriter::class);

// Save it to a file (guesses writer by file extension)
$qrCode->writeFile(__DIR__.'/qrcode.png');

// Create a response object
$response = new Response(
    $qrCode->writeString(SvgWriter::class),
    Response::HTTP_OK,
    ['Content-Type' => $qrCode->getContentType(SvgWriter::class)])
;

// Work via the writer
$writer = new PngWriter($qrCode);
$pngData = $writer->writeString();